package com.watson.nettydemo.demo02;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.SimpleChannelInboundHandler;

import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit;

/**
 * @date: 2022/3/11 15:19
 * @version: 1.0
 */
public class SocketClientHandler  extends SimpleChannelInboundHandler<String> {

    /**
     * msg的消息类型与类的泛型是一致的
     * @param ctx
     * @param msg
     * @throws Exception
     */
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
        System.out.println(ctx.channel().remoteAddress() + "" + msg);
        ctx.writeAndFlush("from client:"+ LocalDateTime.now());
        TimeUnit.MILLISECONDS.sleep(500);
    }
}
